<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>

    // 5、使用 reduce、concat 和递归无限反嵌套多层嵌套的数组

    var arr1 = [1, 2, 3, [1, 2, 3, 4, [2, 3, 4]]];
    function flattenDeep(arr1) {
      return arr1.reduce(
        (acc, val) => {
          console.log(acc,val);
          return Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val,[])
        }

      );
    }
    flattenDeep(arr1); // [1, 2, 3, 1, 2, 3, 4, 2, 3, 4]

  </script>
</html>
